package cn.juni.controller;

import cn.juni.pojo.Permission;
import cn.juni.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author Juni
 * @date 2021/2/26
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    IPermissionService permissionService;

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Permission> permissionList = permissionService.findAll();
        model.addAttribute("permissionList",permissionList);
        return "permission-list";
    }

    @RequestMapping("/save")
    public String save(Permission permission){
        permissionService.insertPermission(permission);
        return "redirect:findAll";
    }
}
